package com.base.mine;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.bean.RoadEntity;
import com.base.mine.adapter.BaseAdapter;
import com.base.mine.adapter.BaseHolder;
import com.base.mine.databinding.ActivityMineroadBinding;
import com.base.mine.presenter.MineRoadPresenter;
import com.base.mine.view.MineRoadView;


/**
 * Created by arvin on 2018/10/29.
 */
@Route(path = "/road/mineroad")
public class MineRoadActivity extends CBaseBarMvpActivity<MineRoadPresenter> implements View.OnClickListener,MineRoadView {

    private ActivityMineroadBinding mBinding;
    private MineRoadPresenter mPresenter;
    private BaseAdapter<RoadEntity> mAdapter;

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityMineroadBinding) mRootBinding;
        setBackNavigation();
        setBarTitle("我的路段");

        mBinding.fab.setOnClickListener(this);
    }

    @Override
    protected void start() {
        mPresenter = new MineRoadPresenter(this,this);
        mAdapter = new BaseAdapter<RoadEntity>(mPresenter.mRoads, mContext) {

            @Override
            public void convert(BaseHolder holder, RoadEntity roadEntity, boolean isHeader, boolean isBottom) {
                TextView name = holder.getView(R.id.name);
                name.setText(roadEntity.getRoadName());
            }
        };
        mAdapter.putNormalType(R.layout.item_mineroad);
        mBinding.rv.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rv.setAdapter(mAdapter);
        mPresenter.start();

    }

    @Override
    public void showMineRoads() {
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.fab) {
            ARouter.getInstance().build("/mine/road").navigation();

        }
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_mineroad;
    }



}
